home *** CD-ROM | disk | FTP | other *** search
/ Clickx 47 / Clickx 47.iso / assets / software / switchproxy.xpi / chrome / switchproxy.jar / content / dialogs / editproxy.js < prev    next >
Encoding:
Text File  |  2006-04-11  |  6.2 KB  |  192 lines

  1.  
  2. var gIsEdit   = false;
  3. var gList;
  4. var gProxyURI;
  5. var gProxy;
  6. var gProxyConfig;
  7. var gProxyNameField;
  8. var gFromProxyManager;
  9.  
  10. function switchProxy_initVals(){
  11.   
  12.   
  13.   //Set Globals
  14.   gProxyNameField  = document.getElementById("proxy-name");
  15.   
  16.   //Edit
  17.   if(window.arguments.length > 1 && window.arguments[0] == "edit" && !switchproxy_isEmpty(window.arguments[1])){
  18.     
  19.     //Proxy URI
  20.     gProxyURI = window.arguments[1];    
  21.     
  22.     gIsEdit  = true;
  23.     try{
  24.       gProxy = switchProxy_ds_getResource(gProxyURI);
  25.     
  26.       //Load Fields
  27.       var gProxyConfig = switchProxy_ds_getPropertyValuesFor(gProxyURI);
  28.       for(key in gSwichProxy_options){
  29.         var oField  = document.getElementById(key);
  30.         var sValue  = gProxyConfig[gSProxyRdfNodeUriRoot + "#" + key];
  31.         
  32.         oField.value = sValue;
  33.       }
  34.       
  35.       //Label
  36.       gProxyNameField.value = gProxyConfig[gSProxyRdfNodeName];
  37.       
  38.       //Set Socks Radio
  39.       oSocks = document.getElementById("networkProxySOCKSVersion");
  40.       if(oSocks.value == "4")
  41.         oSocks.selectedItem = document.getElementById("networkProxySOCKSVersion4");
  42.       else
  43.         oSocks.selectedItem = document.getElementById("networkProxySOCKSVersion5");
  44.       
  45.     }catch(err){ alert(switchproxy_getString("error.unknown")); self.close(); }
  46.   }
  47.   
  48.   //Enable Fields
  49.   switchProxy_enableOptions();
  50.   
  51.   // Thunderbird
  52.   if(navigator.userAgent.search(/Thunderbird/gi) > -1){
  53.       document.getElementById("ftp_row").style.display = "none";
  54.       document.getElementById("gopher_row").style.display = "none";
  55.       document.getElementById("none_row").style.display = "none";
  56.       document.getElementById("none_example_row").style.display = "none";    
  57.   }
  58. }
  59.  
  60. function switchProxy_saveProxy(){
  61.   
  62.   try{
  63.     
  64.     /*
  65.     * Validation
  66.     */
  67.       //Empty
  68.       if(gProxyNameField.value == ""){
  69.         alert(switchproxy_getString("error.add.empty"));
  70.         
  71.         gProxyNameField.focus();
  72.         gProxyNameField.setSelectionRange(0, gProxyNameField.textLength);
  73.         
  74.         return false;
  75.       }
  76.       //Special Chars
  77.       else if(!switchproxy_allowedChars(gProxyNameField.value)){
  78.         alert(switchproxy_getString("error.add.invalid"));
  79.         return false;
  80.       }
  81.       //Can't be named 'None'
  82.       else if(switchproxy_simplify(gProxyNameField.value) == switchproxy_simplify(switchproxy_getString("common.proxy.none"))){
  83.         alert(switchproxy_getString("error.add.duplicate"));
  84.         return false;
  85.       }
  86.         
  87.       //Is This a Duplicate Label?
  88.       var oTestProxy = switchProxy_ds_getElementForValue(gSProxyRdfNodeName, gProxyNameField.value);
  89.       if(oTestProxy != null && (!gIsEdit  || oTestProxy.Value != gProxy.Value)){
  90.         alert(switchproxy_getString("error.add.duplicate"));
  91.         return false;
  92.       }
  93.     
  94.     /*
  95.     * Edit
  96.     */
  97.       if(gIsEdit){
  98.       
  99.         //Update RDF Properties
  100.         for(key in gSwichProxy_options){
  101.           switchProxy_ds_changePropertyValue(gProxy, (gSProxyRdfNodeUriRoot + "#" + key), document.getElementById(key).value);
  102.         }
  103.         
  104.         //Update Name
  105.         switchProxy_ds_changePropertyValue(gProxy, gSProxyRdfNodeName, gProxyNameField.value);
  106.       }
  107.     /*
  108.     * Add
  109.     */
  110.       else{
  111.         var sProxyUri   = opener.switchproxy_getUniqueProxyUri();
  112.         var oProxy    = switchProxy_ds_getResource(sProxyUri);
  113.         
  114.         //Add Element
  115.         switchProxy_ds_addElement(sProxyUri);
  116.         
  117.         //Add Properties
  118.         for(key in gSwichProxy_options){
  119.           var oProp = switchProxy_ds_getResource(gSProxyRdfNodeUriRoot + "#" + key);
  120.           switchProxy_ds_addProperty(oProxy, oProp, document.getElementById(key).value, true);
  121.         }
  122.         
  123.         //Add Name
  124.         switchProxy_ds_addProperty(oProxy, switchProxy_ds_getResource(gSProxyRdfNodeName), gProxyNameField.value, true);
  125.       }
  126.     /*
  127.     * Finish
  128.     */      
  129.       opener.switchproxy_populateList();
  130.       if(gIsEdit){
  131.         
  132.         //Is this proxy is in use, refresh proxy
  133.         var oPrefs  = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
  134.         if(oPrefs.prefHasUserValue("switchproxy.proxy.current") 
  135.           && oPrefs.getCharPref("switchproxy.proxy.current") == gProxy.Value){
  136.           
  137.           opener.switchproxy_doCommand("switchproxy_setProxy()");
  138.         }
  139.         //If not in use, select proxy
  140.         else{
  141.           opener.switchproxy_doCommand("switchproxy_selectItem('"+ gProxyNameField.value +"')");
  142.         }
  143.         
  144.         //alert("Proxy Info Changed");
  145.       }
  146.       else{
  147.         opener.switchproxy_doCommand("switchproxy_selectItem('"+ gProxyNameField.value +"')"); 
  148.         //alert("Proxy Added");
  149.       }
  150.       
  151.   }catch(e){
  152.     alert(switchproxy_getString("error.unknown") +"\n("+ e +")");
  153.     return;
  154.   }
  155.   
  156.   switchproxy_openerFocus()  
  157.   return true;
  158. }
  159.  
  160.  
  161. //Enable or disable Manual
  162. //  + config options
  163. function switchProxy_enableOptions(){
  164.   var disable = !(document.getElementById("networkProxyType").value == "1"); //if 1 then manual is selected
  165.   
  166.   //Set Radios
  167.   oType = document.getElementById("networkProxyType");
  168.   if(!disable){
  169.     oType.selectedItem = document.getElementById("type-manual-radio");
  170.   }
  171.   else{
  172.     oType.selectedItem = document.getElementById("type-auto-radio");
  173.   }
  174.   
  175.   //Manual Options
  176.   document.getElementById("networkProxyHTTP").disabled = disable;
  177.   document.getElementById("networkProxyHTTP_Port").disabled = disable;
  178.   document.getElementById("networkProxySSL").disabled = disable;
  179.   document.getElementById("networkProxySSL_Port").disabled = disable;
  180.   document.getElementById("networkProxyFTP").disabled = disable;
  181.   document.getElementById("networkProxyFTP_Port").disabled = disable;
  182.   document.getElementById("networkProxyGopher").disabled = disable;
  183.   document.getElementById("networkProxyGopher_Port").disabled = disable;
  184.   document.getElementById("networkProxySOCKS").disabled = disable;
  185.   document.getElementById("networkProxySOCKS_Port").disabled = disable;
  186.   document.getElementById("networkProxySOCKSVersion4").disabled = disable;
  187.   document.getElementById("networkProxySOCKSVersion5").disabled = disable;
  188.   document.getElementById("networkProxyNone").disabled = disable;
  189.   
  190.   //Auto
  191.   document.getElementById("networkProxyAutoconfigURL").disabled = !disable;
  192. }